package com.scunewscreeper.repository;

import com.scunewscreeper.entity.StarTNews;
import com.scunewscreeper.vo.StarNewsVO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: 大龙
 * \* Date: 2021/11/14
 * \* Time: 20:12
 * \* Description:
 * \
 */
public interface StarTNewsRepository extends JpaRepository<StarTNews,Integer> {
    /**
     * 返回按收藏时间排序的用户收藏列表
     * @param openId
     * @return java.util.List<com.scunewscreeper.entity.StarTNews>
     */
    @Query("select new com.scunewscreeper.vo.StarNewsVO(news.sId.sNewsid,news.sStarttime,data.dSource,data.dType,data.dTitle,data.dPhoto)"+
            "from StarTNews news LEFT JOIN DataTNews data on news.sId.sUserid=?1 and news.sId.sNewsid=data.dId order by news.sStarttime desc ")
    List<StarNewsVO> GetStarNews(String openId);

    @Query("select news from StarTNews news where news.sId.sNewsid=?1 and news.sId.sUserid=?2")
    StarTNews findStarTNewsByNewsIdAndOpenId(String newsId,String openId);

}
